package ui.activity.login.biz;

import Bean.JiFenRecordBean;
import Bean.LoginBean;
import Bean.SiteAddressBean;
import base.BaseBiz;
import base.BaseResp;
import coom.BaseSubscribe;
import coom.RetrofitHelp;
import okhttp3.RequestBody;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;
import ui.model.IntegralTotalBean;

/**
 * Created by chenjian on 19/2/26.
 * 1
 */

public class LoginBiz extends BaseBiz {


    /**
     * 获取登录注册
     */
    public void getLogin(RequestBody requestBody, final Callback<LoginBean.DataBean> callback) {
        com.add(RetrofitHelp.getSecretApi().login(requestBody)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<LoginBean.DataBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((LoginBean.DataBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((LoginBean.DataBean) obj);
                    }
                })
        );
    }
    /**
     * 获取登录注册
     */
    public void putUmtoken(RequestBody requestBody, final Callback<Boolean> callback) {
        com.add(RetrofitHelp.getSecretApi().putUmToken(requestBody)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<Boolean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((Boolean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((Boolean) obj);
                    }
                })
        );
    }

    /**
     * 获取积分信息
     */
    public void integralTotal(String id, final Callback<IntegralTotalBean> callback) {
        com.add(RetrofitHelp.getSecretApi().integralTotal(id)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<IntegralTotalBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((IntegralTotalBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((IntegralTotalBean) obj);
                    }
                })
        );
    }
    /**
     * 获取积分记录
     */
    public void integralRecord(String id,String year,String month,String type, final Callback<JiFenRecordBean> callback) {
        com.add(RetrofitHelp.getSecretApi().integralTotalRecord(id,year,month,type)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<JiFenRecordBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((JiFenRecordBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((JiFenRecordBean) obj);
                    }
                })
        );
    }

    /**
     * 获取积分记录
     */
    public void jifenrecord(String year,String month,String type, final Callback<JiFenRecordBean> callback) {
        com.add(RetrofitHelp.getSecretApi().jifenrecord(year,month,type)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<JiFenRecordBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((JiFenRecordBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((JiFenRecordBean) obj);
                    }
                })
        );
    }
    /**
     * 获取发货地址
     */
    public void getAddress( final Callback<SiteAddressBean> callback) {
        com.add(RetrofitHelp.getSecretApi().siteAddress()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseSubscribe<BaseResp<SiteAddressBean>>() {

                    @Override
                    public void onSuccess(Object obj) {
                        callback.onSuccess((SiteAddressBean) obj);
                    }

                    @Override
                    public void onFailure(Object obj) {
                        callback.onFailure((SiteAddressBean) obj);
                    }
                })
        );
    }


}
